'''
Created on Apr 26, 2012
TC ID: Ecom_5027
Desc: Kiem thu chuc nang tao mot thong bao
@author: lavang
'''
import unittest
from HTMLTestRunner import HTMLTestRunner
import time
from Functions.globalFunc import readData, preCondition, endCondition
from Functions.loginPageFunc import login
from Functions.announcementFunc import clickOnGoToAnnouncement,\
    clickOnLinkAddAnnouncement,createAnnouncement,\
    isAnnouncementCreatedSuccessfully

username=readData("username")
password=readData("password")
tm_content='this is announcement about Efront'
tm_announcementName=readData("announcementName")
class Ecom_5027(unittest.TestCase):


    def setUp(self):
        preCondition(self)

    def test_Ecom_5027(self):
        print "Buoc 1: Dang nhap vao website"
        login(self,username,password)
        
        print "Buoc 2: Click 'Go to announcement page' "
        clickOnGoToAnnouncement(self)
        
        print "Buoc 3: Click 'Add announcement' "
        clickOnLinkAddAnnouncement(self)
        
        print "Buoc 4: Tao mot thong bao moi"
        createAnnouncement(self,title=tm_announcementName,day='25',month='Apr',year='2012',hour='18',mins='30',eDay='26',eMonth='Apr',eYear='2012',eHour='19',eMins='15',content=tm_content,createEvent='on',sendNotification='on')
    
        print "Buoc 5: Xac nhan tao thong bao thanh cong"
        self.assertTrue(isAnnouncementCreatedSuccessfully(self,tm_announcementName), "Failed!")
        print "Passed! Thong bao duoc tao thanh cong"
    
    def tearDown(self):
        endCondition(self)

if __name__ == "__main__":
    #import sys;sys.argv = ['', 'Test.testName']
    testSuite = unittest.TestSuite()
    suite = unittest.TestLoader().loadTestsFromTestCase(Ecom_5027)
    dateTime = time.strftime('%Y%m%d_%H_%M_%S')
    buf = file("../../Report/TestResults" + "_" + dateTime + ".html",'wb')
    runner = HTMLTestRunner(
                    stream=buf,
                    title='Test Results',
                    description='Kiem thu chuc nang tao mot thong bao'
                    )
    runner.run(suite)